﻿<%@ WebHandler Language="C#" Class="changePassword" %>

using System;
using System.Web;
using OneShoppingBLL;
using OneShoppingModel;
using OneshoppingWeb;
using OneShoppingUtility;
using System.Web.SessionState; 

public class changePassword : IHttpHandler, IRequiresSessionState
{
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        try
        {
            SystemUser sysUser = (SystemUser)context.Session["user"];
            string loginName = sysUser.LoginName;
            string oldPassword = context.Request["oldPassword"];
            string newPassword = context.Request["newPassword"];
            string againNewPassword = context.Request["againNewPassword"];
            if (newPassword != againNewPassword)
            {
                context.Response.Write(UtilityJson.ResultToJson((int)Protocol_user.PASSWORD_DIF));//两次密码不一样
                return;
            }
            
            if (sysUser.LoginPwd!=oldPassword)
            {
                context.Response.Write(UtilityJson.ResultToJson((int)Protocol_user.PASSWORD_ERROR));//密码错误
                return;
            }
           sysUser.LoginPwd = newPassword;
           bool result= SystemUserBLL.GetInstance().Update(sysUser);
        
           if (result == true)
           {
               context.Response.Write(UtilityJson.ResultToJson((int)Protocol_user.UPDATEPASSWORD_SUCCESS));//修改成功
           }
           else {
               context.Response.Write(UtilityJson.ResultToJson((int)Protocol_user.REGISTER_FAIL));//修改失败
           }
        }
        catch
        {
            context.Response.Write(UtilityJson.ResultToJson((int)Protocol_user.NOT_LOG));//没有登入
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}